package com.suncaper.shop.config;


import com.suncaper.shop.component.LoginHandlerInterceptor;
import com.suncaper.shop.component.MyLocaleResolver;
import com.suncaper.shop.component.SalerLoginInterceptor;
//import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
//import org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.*;

//使用WebMvcConfigurerAdapter可以来扩展SpringMVC的功能
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/about_us.html").setViewName("aboutus");
        registry.addViewController("/cart.html").setViewName("cart");
        registry.addViewController("/order.html").setViewName("order");
        registry.addViewController("/addresses.html").setViewName("addresses");
        registry.addViewController("/shop.html").setViewName("shop");
        registry.addViewController("/create_account.html").setViewName("login");
        registry.addViewController("/account_details.html").setViewName("accountdetails");
        registry.addViewController("/wishlist.html").setViewName("wishlist");
        registry.addViewController("/shop_right_sidebar.html").setViewName("shop");
        registry.addViewController("/deals.html").setViewName("deals");
        registry.addViewController("/simple_product.html").setViewName("/simple_product");
    }

    /**
     * 添加拦截器
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor())
                .addPathPatterns("/checkout", "/order");

        registry.addInterceptor(new SalerLoginInterceptor()).addPathPatterns("/salerorder", "/account_saler");
    }

    @Bean
    public LocaleResolver localeResolver() {
        return new MyLocaleResolver();
    }


}
